//
//  DHCaseManageViewController.m
//  发;fjag
//
//  Created by 刘鹏飞 on 2016/11/14.
//  Copyright © 2016年 刘鹏飞. All rights reserved.
//

#import "DHCaseManageViewController.h"
#import "XHHAdditions.h"
#import <Masonry.h>
#import "DHAddCaseViewController.h"
#import "DHCaseManageCell.h"
#import "DHAddCaseModel.h"

static NSString *ID = @"ManageViewCell";
@interface DHCaseManageViewController ()<UITableViewDelegate,UITableViewDataSource>

/*---数据源数组---*/
@property (nonatomic,strong)NSMutableArray *modelArrM;

@property (nonatomic,strong)NSArray *modelArr;

/*---tabel---*/
@property (nonatomic,strong)UITableView *tabelView;

@end

@implementation DHCaseManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.modelArrM = [NSMutableArray array];
    self.view.backgroundColor = [UIColor XHH_colorWithHex:0xEFEFF5];
    
}

-(void)xhhSetupSubviews {
    //----创建taabelView----//
    UITableView *tabelView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:tabelView];
    self.tabelView = tabelView;
    
    //设置代理
    tabelView.dataSource = self;
    tabelView.delegate = self;
    
    //注册cell
    [tabelView registerNib:[UINib nibWithNibName:@"DHCaseManageCell"  bundle:nil] forCellReuseIdentifier:ID];
    
    //设置tabelView属性
    tabelView.separatorStyle = NO;
    tabelView.showsVerticalScrollIndicator = NO;
    tabelView.showsHorizontalScrollIndicator = NO;
    tabelView.bounces = NO;
    tabelView.rowHeight = 150;
    
    //----创建添加病例按钮----//
    UIButton *clickBtn = [[UIButton alloc] init];
    [self.view addSubview:clickBtn];
    
    [clickBtn setImage:[UIImage imageNamed:@"add_40x40"] forState:UIControlStateNormal];
    [clickBtn setTitle:@"添加病例" forState:UIControlStateNormal];
    clickBtn.backgroundColor = [UIColor whiteColor];
    [clickBtn setTitleColor:[UIColor cyanColor] forState:UIControlStateNormal];
    
    //添加点击事件
    [clickBtn addTarget:self action:@selector(addCaseAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //布局
    [clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.height.mas_equalTo(50);
    }];
    
}


-(void)addCaseAction:(UIButton *)sender {
    
    DHAddCaseViewController *addCaseViewController = [[DHAddCaseViewController alloc] init];
    void (^myBlock)() = ^(DHAddCaseModel *model){
        [self.modelArrM addObject:model];
        self.modelArr = self.modelArrM;
        [self.tabelView reloadData];
    };
    addCaseViewController.myTapBlock = myBlock;
    [self.navigationController pushViewController:addCaseViewController animated:YES];
    
}

-(void)xhhSetupNavigationItems {
    
    self.navigationItem.title = @"病历管理";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}

#pragma mark - 实现数据源方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.modelArr.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DHCaseManageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.model = self.modelArr[indexPath.row];
    cell.backgroundColor = [UIColor XHH_colorWithHex:0xEFEFF5];
    
    return cell;
}


@end
